package edu.guigu.todolist.login.presenter;

import edu.guigu.todolist.login.model.LoginModel;
import edu.guigu.todolist.login.view.LoginView;
import edu.guigu.todolist.login.model.LoginModelImpl;

public class LoginPresenterImpl implements LoginPresenter{

    private LoginView loginView;

    private LoginModel loginModel;

    public LoginPresenterImpl(LoginView loginView) {
        this.loginModel = new LoginModelImpl();
        this.loginView = loginView;
        this.loginView.initView();
    }

    @Override
    public void loginVerify(String username, String password) {
        // 执行业务逻辑处理, 通过回调方法，进行视图处理
        loginModel.requestLogin(username,password, new LoginModelImpl.Callback() {
            @Override
            public void onSuccess() {
                loginView.navigateToTodo();
            }

            @Override
            public void onFailed() {
                loginView.showLoginFailed();
            }
        });
    }

    @Override
    public void onDestroy() {
        if (loginView != null) {
            loginView = null;
        }
    }
}
